<?php
include 'test_header.php';

class test_judge_result_process extends UnitTestCase{
	
	private $db ; 

	function setUp(){
		$this->db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `result` (
  `judge_no` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `code_file_name` varchar(64) NOT NULL,
  `judge_time` varchar(128) NOT NULL,
  `problem_no` int(11) NOT NULL,
  `username` varchar(256) NOT NULL,
  `result` varchar(1024) NOT NULL,
  `time_spend` varchar(128) NOT NULL,
  `memory_spend` varchar(128) NOT NULL,
  `language` varchar(32) NOT NULL ,
  PRIMARY KEY (`code_file_name`),
  UNIQUE KEY `judge_no` (`judge_no`),
  KEY `judge_time` (`judge_time`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
";

$res = $this->db->query( $sql );

$sql = "
INSERT INTO `result` (`judge_no`, `code_file_name`, `judge_time`, `problem_no`, `username`, `result`, `time_spend`, `memory_spend`, `language`) VALUES
(19, 'test.c', '1276257725', 1001, 'anonymous', 'Accepted', '0.498000', '0', 'c')
";

$res = $this->db->query( $sql );
	
	}

	function tearDown(){
		
		$sql = "drop table result";

		$res = $this->db->query( $sql );
	
	}

	function test_insert_new_result_into_database(){

		$result = '{ "user":"anonymous", "problem_no":"1001", "result":"Accepted", 
			"judgetime":"1276257725", "time_spend":"0.498000", "memory_spend":"0", "language":"c" }' ;
		$result = json_decode( $result , true );

		//@todo 代码文件名是一个问题
		$result['code_file_name'] = '123.c' ;

		$judge_result_proc = new judge_result_process( $this->db );
		$this->assertTrue( $judge_result_proc->insert_new_result( $result ) );
		
	}

	function test_get_all_result(){
		
		$judge_result_proc = new judge_result_process( $this->db );
		$this->assertTrue( $judge_result_proc->get_all_result() );
	}
}
	

$test = new test_judge_result_process();
$test->run( new HtmlReporter() );

